package com.tangcco.lockwell.service.impl;

import com.tangcco.lockwell.repository.SubjectMapper;
import com.tangcco.lockwell.service.SubjectService;
import com.tangcco.lockwell.viewmodel.admin.subject.SubjectVM;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.security.auth.Subject;
import java.util.Collections;
import java.util.List;

@Service
public class SubjectServiceImpl extends BaseServiceImpl<SubjectVM> implements SubjectService {
    @Resource
    private final SubjectMapper subjectMapper;

    public SubjectServiceImpl(SubjectMapper subjectMapper) {
        super(subjectMapper);
        this.subjectMapper = subjectMapper;
    }

    //添加学科
    public int insert(SubjectVM subjectVM) {
        return super.insert(subjectVM);
    }

    //修改学科
    public int updateById(SubjectVM record) {
        return super.updateById(record);
    }

    @Override
    public List<SubjectVM> selectLelevl1() {
        return subjectMapper.selectLevel1();
    }

    //查询所有主学科
    @Override
    public List<SubjectVM> selectAllMainSubject() {
        return subjectMapper.selectAllMainSubject();
    }

    @Override
    public List<SubjectVM> selectAllSubject(Integer parentId) {
        return subjectMapper.selectAllSubject(parentId);
    }

    //查询所有学科
//    @Override
//    public List<Subject> selectAllSubject(@Param("parentId") Integer parentId) {
//        return subjectMapper.selectAllSubject(parentId);
//    }

    //学科条件分页查询
    @Override
    public List<SubjectVM> selectSubjectByPage(SubjectVM subjectVM) {
        Integer pageIndex = subjectVM.getPageIndex();
        if(pageIndex!=null){
            pageIndex = (pageIndex -1)*subjectVM.getPageSize();
            subjectVM.setPageIndex(pageIndex);
        }
        List<SubjectVM> list=subjectMapper.selectSubjectByPage(subjectVM);
        return list;
    }

    //学科详情查询
    @Override
    public SubjectVM selectSubjectById(Integer id) {
        return subjectMapper.selectSubjectById(id);
    }

    @Override
    public List<SubjectVM> selectAll() {
        return subjectMapper.selectAll();
    }

    //删除学科
    @Override
    public int deleteById(Integer id) {
        return super.deleteById(id);
    }
}
